package com.hndzyu.yd.base;

import android.content.Intent;
import android.support.multidex.MultiDexApplication;
import android.widget.Toast;

import com.dpuntu.downloader.DownloadManager;
import com.liulishuo.filedownloader.FileDownloader;
import com.mob.MobSDK;
import com.hndzyu.yd.ui.UpgradeActivity;
import com.hndzyu.yd.utils.AdPreference;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.UpgradeInfo;
import com.tencent.bugly.beta.upgrade.UpgradeListener;
import com.tencent.bugly.beta.upgrade.UpgradeStateListener;

/**
 * Created by zz9527 on 2018/10/12.
 */
public class BaseApplication extends MultiDexApplication {
    public static boolean starShare=false;
    public static int taskposition=0;
    @Override
    public void onCreate() {
        super.onCreate();
        new AdPreference(this);
        DownloadManager.initDownloader(this);
        FileDownloader.setup(this);
        MobSDK.init(this);
        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        Beta.autoInit = false;
        Beta.upgradeListener = new UpgradeListener() {
            @Override
            public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean isSilence) {
                if (strategy != null) {
                    Intent i = new Intent();
                    i.setClass(getApplicationContext(), UpgradeActivity.class);
                    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(i);
                } else {
                    Toast.makeText(BaseApplication.this, "当前为最新版本", Toast.LENGTH_SHORT).show();
                }
            }
        };

        /* 设置更新状态回调接口 */
        Beta.upgradeStateListener = new UpgradeStateListener() {
            @Override
            public void onUpgradeSuccess(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_SUCCESS",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onUpgradeFailed(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_FAILED",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onUpgrading(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_CHECKING",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDownloadCompleted(boolean b) {

            }

            @Override
            public void onUpgradeNoVersion(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_NO_VERSION",Toast.LENGTH_SHORT).show();
            }
        };
        Bugly.init(getApplicationContext(), "f9e3c29857", true);
    }
}
